package cn.myfirefly.moming.portal.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.myfirefly.moming.common.model.DataAuthObjectDto;
import cn.myfirefly.moming.common.model.DataAuthObjectFilterDto;
import cn.myfirefly.moming.common.service.DataAuthObjectService;
import cn.myfirefly.core.BaseController;
import cn.myfirefly.core.Const;
import cn.myfirefly.core.annotation.BjuiDataGridFilterDtoWrap;
import cn.myfirefly.core.model.PageResultDto;
import cn.myfirefly.core.model.ResultDto;

@Controller
@RequestMapping("dataAuthObject")
public class DataAuthObjectController extends BaseController {

	@Autowired
	private DataAuthObjectService mmDataAuthObjectService;
	
	@RequestMapping("index.do")
	public String index(HttpServletRequest request, 
			HttpServletResponse response) {
		return "dataauthobject/index";
	}
	
	@RequestMapping("edit.do")
	public String edit(HttpServletRequest request, 
			HttpServletResponse response) {
		
		return "dataauthobject/edit";
	}
	
	@RequestMapping("add.do")
	public String add(HttpServletRequest request, 
			HttpServletResponse response) {
		
		return "dataauthobject/edit";
	}
	
	@RequestMapping("addSave.do")
	@ResponseBody
	public ResultDto addSave(DataAuthObjectDto dto, HttpServletRequest request, 
			HttpServletResponse response) {
		if (dto.getId() != null) {
			return error("请求参数错误");
		}
		warpModifyInfo(dto, request, true);
		mmDataAuthObjectService.insert(dto);
		return success("保存成功");
	}
	
	@RequestMapping("editSave.do")
	@ResponseBody
	public ResultDto editSave(DataAuthObjectDto dto, HttpServletRequest request, 
			HttpServletResponse response) {
		if (dto.getId() == null) {
			return error("请求参数错误");
		}
		warpModifyInfo(dto, request);
		mmDataAuthObjectService.update(dto);
		return success("保存成功");
	}
	
	@SuppressWarnings("rawtypes")
	@RequestMapping("list.do")
	@ResponseBody
	@BjuiDataGridFilterDtoWrap
	public PageResultDto list(DataAuthObjectFilterDto dto, HttpServletRequest request, 
			HttpServletResponse response) {
		PageResultDto result = mmDataAuthObjectService.getList(dto);
		return result;
	}
	
	@RequestMapping("get.do")
	@ResponseBody
	public ResultDto getMmDataAuthObject(DataAuthObjectDto dto, HttpServletRequest request, 
			HttpServletResponse response) {
		DataAuthObjectDto mmDataAuthObject = mmDataAuthObjectService.getDataAuthObject(dto.getId());
		return success(mmDataAuthObject);
	}
	
	@RequestMapping("del.do")
	@ResponseBody
	public ResultDto del(DataAuthObjectDto dto, HttpServletRequest request, 
			HttpServletResponse response) {
		String msg = mmDataAuthObjectService.del(dto.getId());
		if (!Const.ResultCode.SUCCESS.equals(msg)) {
			return error(msg);
		}
		return success("删除成功");
	}
}
